﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms.Design;

namespace Marmat.Forms
{
    public class BarItemCollectionUITypeEditor : System.Drawing.Design.UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edsvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (edsvc != null)
            {
                var frm = new Marmat.Forms.Design.CollectionEditorForm<BarItem>(value as IList<BarItem>);
                if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    context.OnComponentChanged();
                }
            }
            return value;
        }
    }
}
